package routers

import (
	"github.com/DeanThompson/ginpprof"
	"github.com/gin-gonic/gin"
	"go_auth/controller/admin"
	"go_auth/controller/users"
	"go_auth/middleware"
)

func InitRouter() *gin.Engine {

	r := gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	adm := r.Group("/admin/api/v1")
	{
		//轮播图批量修改
		adm.POST("/ad", admin.UpdateAd)
		adm.GET("/ad", admin.GetAllAd)
	}
	user := r.Group("/user/api/v1")
	user.POST("/login", users.Login)

	user.Use(middleware.JWT())
	{
		//注册添加用户
		user.POST("/register", users.Register)
		user.POST("/aregister", users.ARegister)
		user.GET("/users", users.FindUsers)
		user.POST("/users", users.UpdatePassword)
		user.POST("/role", users.Role)
		user.GET("/role", users.FindRoles)
		user.POST("/staff", users.SetAdmin)

		user.POST("/source", users.Source)
		user.GET("/source", users.FindSources)

		//权限
		user.GET("/per", users.GetAllPer)
		user.POST("/per", users.Per)

		//黑名单
		user.POST("/blacklist", admin.BlackList)

		//goldeye

	}

	ginpprof.Wrap(r)
	return r
}
